﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microhard.WST.BI.Buz.Models;
using AutoMapper;
using Microhard.WST.BI.Buz.DataAccess;

namespace Microhard.WST.BI.Buz.DTO
{
    public static class DTOMapExtension
    {
        #region ContractModel
        public static ContractModel ToModel(this PM_Contracts entity)
        {
            var model = Mapper.Map<ContractModel>(entity);
            return model;
        }

        public static PM_Contracts ToEntity(this ContractModel model)
        {
            return Mapper.Map<PM_Contracts>(model);
        }
        #endregion

        #region ContractReg
        public static ContractRegModel ToModel(this PM_Customer_ContractReg entity)
        {
            var model = Mapper.Map<ContractRegModel>(entity);
            model.Customer = entity.PM_Customers.ToModel();
            return model;
        }

        public static PM_Customer_ContractReg ToEntity(this ContractRegModel model)
        {
            return Mapper.Map<PM_Customer_ContractReg>(model);
        }
        #endregion

        #region OrderDetail
        public static OrderDetailModel ToModel(this PM_OrderSheetDetail entity)
        {
            var model = Mapper.Map<OrderDetailModel>(entity);
            return model;
        }

        public static PM_OrderSheetDetail ToEntity(this OrderDetailModel model)
        {
            return Mapper.Map<PM_OrderSheetDetail>(model);
        }
        #endregion

        #region Order
        public static OrderModel ToModel(this PM_Order entity)
        {
            var model = Mapper.Map<OrderModel>(entity);
            model.RegInfo = entity.PM_Customer_ContractReg.ToModel();
            
            return model;
        }

        public static PM_Order ToEntity(this OrderModel model)
        {
            return Mapper.Map<PM_Order>(model);
        }
        #endregion

        #region OrderPrdDetail
        public static OrderPrdDetailModel ToModel(this PM_OrderPrdDetail entity)
        {
            var model = Mapper.Map<OrderPrdDetailModel>(entity);
            model.Order = entity.PM_Order.ToModel();

            return model;
        }

        public static PM_OrderPrdDetail ToEntity(this OrderPrdDetailModel model)
        {
            return Mapper.Map<PM_OrderPrdDetail>(model);
        }
        #endregion

        #region Customer
        public static CustomerModel ToModel(this PM_Customers entity)
        {
            var model = Mapper.Map<CustomerModel>(entity);
            return model;
        }

        public static PM_Customers ToEntity(this CustomerModel model)
        {
            return Mapper.Map<PM_Customers>(model);
        }
        #endregion
    }
}
